package proxy

import (
	"fmt"
	"go_keep_learning/jtthink/design_patterns/proxy/model"
)

type LoginFunc func(userName, password string)

// TODO :不能理解 <07-04-22, yourname> //
type LogDecorator func(f LoginFunc) LoginFunc

//代理
type UserProxy struct {
	user *model.User
}

func (this *UserProxy) Login(decorator LogDecorator) LoginFunc {
	//主业务
	//装饰器
	return decorator(this.user.Login)
}

func NewUserProx(u *model.User) *UserProxy {

	return &UserProxy{user: u}
}

func LogtoRedis(f LoginFunc) LoginFunc {
	return func(userName, password string) {
		fmt.Println("日志写到redis")
		f(userName, password)
	}
}
func LogtoMysql(f LoginFunc) LoginFunc {
	return func(userName, password string) {
		fmt.Println("日志写到mysql")
		f(userName, password)
	}
}
